#include<bits/stdc++.h>
using namespace std;
const int N=4e5+10;
int n,a,b,flg[N],nd,ed,ans;
vector<int> edge[N];
inline void dfs(int u){
	flg[u]=1;
	nd++,ed+=edge[u].size();
	for(auto &i:edge[u])
		if(!flg[i]) dfs(i);
}
signed main(){
	freopen("pairint.in","r",stdin);
	freopen("pairint.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		edge[a].push_back(b),edge[b].push_back(a);
	}
	for(int i=1;i<=2*n;i++)
		if(!flg[i]){
			nd=ed=0;
			dfs(i);
			ed/=2,ans+=min(nd,ed);
		}
	cout<<ans;
	return 0;
}